Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid undelivered notifications error #1335

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AngusMorton
Copy link

Maybe closes: #1306

I have yet to validate that this change fixes anything. I plan to test this and see if it reduces the error rate. I will comment once I've tested this in production and confirmed that it resolves the errors.

Based on the ResizeObserver documentation, I suspect that calling readBrowserProperties() forces a synchronous layout, which then enqueues a new resize observer notification if the body size changes when the layout is re-calculated.

@snowplowcla snowplowcla added the cla:no [Auto generated] Snowplow Contributor License Agreement has not been signed. label Jul 23, 2024
@snowplowcla
Copy link

Thanks for your pull request. Is this your first contribution to a Snowplow open source project? Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://docs.snowplowanalytics.com/docs/contributing/contributor-license-agreement/ to learn more and sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.

Copy link
Contributor

@jethron jethron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after comments if LGT @matus-tomlein. Look forward to the results of your testing!

We should probably make getBrowserProperties only do the expensive stuff conditionally as well; 1/3 callers don't even use the expensive viewport/documentSize values and it's when the tracker first loads so probably a bad time to be forcing reflow.

}
});
resizeObserver.observe(document.body);
resizeObserver.observe(document.documentElement);
}

function scheduleBrowserPropertiesCallback(func: () => void) {
if (requestAnimationFrame) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to check with typeof or against window or it will still throw is not defined (though I'm not sure we offically still support anything that doesn't support rAF anyway).

Copy link
Author

@AngusMorton AngusMorton Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we offically still support anything that doesn't support rAF anyway

Assuming the browserslistrc is up to date, it looks like IE 9 is in the supported list of browsers, which doesn't support rAF. I'll remove the fallback, though, since ResizeObserver is less well-supported than rAF, this code path won't be (as far as I can tell) called by any browsers that don't support rAF.

@AngusMorton
Copy link
Author

We should probably make getBrowserProperties only do the expensive stuff conditionally as well; 1/3 callers don't even use the expensive viewport/documentSize values and it's when the tracker first loads so probably a bad time to be forcing reflow.

I'm happy to make that change if you're open to it, I can do it in a separate PR.

@AngusMorton AngusMorton force-pushed the am/avoid-undelivered-notifications branch from d7e21a7 to e9c77be Compare July 30, 2024 02:55
@AngusMorton
Copy link
Author

I signed it!

@snowplowcla
Copy link

Confirmed! @AngusMorton has signed the Contributor License Agreement. Thanks so much.

@snowplowcla snowplowcla added cla:yes [Auto generated] Snowplow Contributor License Agreement has been signed. and removed cla:no [Auto generated] Snowplow Contributor License Agreement has not been signed. labels Jul 30, 2024
Copy link
Contributor

@matus-tomlein matus-tomlein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the browser compatibility, this looks good to me too!

But would be good to get some validation if this actually helps. I have unfortunately been unable to reproduce the issue thus far, so can't test it out. If you have a way to validate it, please do and let us know!

// queried. It's possible that the forced synchronous layout causes the ResizeObserver
// to be fired again, leading to an infinite loop and the "ResizeObserver loop completed
// with undelivered notifications" error.
readBrowserPropertiesTask = requestAnimationFrame(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the requestAnimationFrame API is not supported on all browsers that the JS tracker v3 supports. Could we check if the API is available in the browser and avoid using it if not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes [Auto generated] Snowplow Contributor License Agreement has been signed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ResiezObserver loop completed with undelivered notifications
4 participants